<?php
namespace App\Controllers;

use App\Library\App;
use App\Models\SysUser;
use App\Models\SysRole;

class IndexController extends BaseController {

    public function initialize() {
        parent::initialize();
    }

    public function indexAction() {
        $this->display("/index/index");
    }

    public function headerAction() {
        $this->display("/index/header");
    }

    public function sidebarAction() {
        $uid = App::getCurrentUserUid();
        if($uid === false) {
            return;
        }
        $user   = new SysUser();
        $entity = $user->get($uid);
        if($entity === false || !isset($entity['role_id'])) {
            return;
        }
        if($entity['status'] != 1) {
            return;
        }
        $role       = new SysRole();
        $roleEntity = $role->get($entity['role_id']);
        if($roleEntity['status'] != 1) {
            return;
        }
        if($roleEntity === false || !isset($roleEntity['purview'])) {
            return;
        }
        $purview = json_decode($roleEntity['purview'], true);
        $this->display("/index/sidebar", [
            'purview' => $purview
        ]);
    }
}
